package com.woniuxy.yoga.progress.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import com.woniuxy.yoga.progress.dao.model.Expcard;
import com.woniuxy.yoga.progress.model.form.CreateExpCardForm;
import com.woniuxy.yoga.progress.model.param.CreateExpCardParam;
import com.woniuxy.yoga.progress.service.ExpcardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 体验卡流程表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/expcard")
@Api(tags = "体验卡进度管理")
@Validated
public class ExpcardController {

    @Autowired
    private ExpcardService expcardService;

    /**
     * 通过订单号查询体验卡进度
     * @param orderNum 订单编号
     * @return Expcard
     */
    @GetMapping("/getByOrderNum/{orderNum}")
    @ApiOperation("通过订单号查询体验卡进度")
    @YogaLog("通过订单号查询体验卡进度")
    public Result<Expcard> getByOrderNum(@PathVariable("orderNum") @Valid @NotNull String orderNum){
        Expcard expcard = expcardService.getByOrderNum(orderNum);
        return Result.getResult(Expcard.class).setMessage("查询成功").setData(expcard);
    }

    /**
     * 通过用户id查询体验卡进度
     * @param userId 订单编号
     * @return Expcard
     */
    @GetMapping("/getByUserId/{userId}")
    @ApiOperation("通过用户id查询体验卡进度")
    @YogaLog("通过用户id查询体验卡进度")
    public Result<Expcard> getByUserId(@PathVariable("userId") @Valid @NotNull Integer userId){
        Expcard expcard = expcardService.getByUserId(userId);
        return Result.getResult(Expcard.class).setMessage("查询成功").setData(expcard);
    }

    /**
     * 创建体验课进度表
     * @param form 创建体验课进度表参数
     * @return String
     */
    @PostMapping("/createExpCard")
    @ApiOperation("创建体验课进度表")
    @YogaLog("创建体验课进度表")
    public Result<?> createExpCard(@RequestBody @Valid CreateExpCardForm form){
        expcardService.createExpCard(BeanUtil.toBean(form, CreateExpCardParam.class));
        return Result.getResult().setMessage("创建体验课进度表成功");
    }

    /**
     * 完成体验课
     * @param expcardId 参数
     */
    @GetMapping("/finishExpcard/{expcardId}")
    @ApiOperation("完成体验课")
    @YogaLog("完成体验课")
    public Result<?> finishExpcard(@PathVariable("expcardId") Integer expcardId){
        expcardService.finishExpcard(expcardId);
        return Result.getResult().setMessage("操作成功");
    }

    /**
     * 查询用户未完成体验卡
     * @param userId userid
     * @return Expcard
     */
    @GetMapping("/selectUnfinishExp/{userId}")
    @ApiOperation("查询用户未完成体验卡")
    @YogaLog("查询用户未完成体验卡")
    public Result<Expcard> selectUnfinishExp(@PathVariable("userId") @Valid @NotNull Integer userId){
        Expcard expcard = expcardService.selectUnfinishExp(userId);
        return Result.getResult(Expcard.class).setMessage("查询成功").setData(expcard);
    }
}

